<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
    >
      <el-form-item label="学校" prop="schoolName">
        <el-input
          v-model="queryParams.schoolName"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单" prop="params[id]">
        <el-input
          v-model="queryParams['params[id]']"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

     
      <el-form-item label="配送时间" prop="sendTime">
        <el-date-picker
          v-model="sendTime"
          type="daterange"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table border v-loading="loading" :data="menusList">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column label="序号" align="center" type="index" width="50" />

      <el-table-column label="学校名称" align="center" prop="schoolName">
      </el-table-column>
      <el-table-column label="供应商" align="center" prop="deptName">
      </el-table-column>
      <el-table-column label="采购单" align="center" prop="id">
      </el-table-column>
      <el-table-column label="配送时间" align="center" prop="sendTime">
      </el-table-column>
      <el-table-column label="应收金额" align="center" prop="money">
      </el-table-column>

      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        width="180"
      >
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        fixed="right"
        class-name="small-padding fixed-width"
        width="200"
      >
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="seeInfo(scope.row)"
            >修改</el-button
          >

          <el-button size="mini" type="text" @click="seeExpo(scope.row)"
            >导出</el-button
          >
          <!-- <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              >删除</el-button
            > -->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加或修改菜谱对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="80%"
      append-to-body
      class="universal-from"
      :before-close="handleClose"
    >
      <addPro
        :mId="menusId"
        v-if="open"
        @cancel="open = false"
        @submitForm="submitForm"
      ></addPro>
    </el-dialog>
  </div>
</template>
    
    <script>
import { getDelivery, getDeliveryInfo } from "@/api/system/procure";
import { getFormatbrandData } from "@/api/system/brand";
import { getFormatCateData } from "@/api/system/cate";
import addPro from "./add";
import { getFormatSpecData } from "@/api/system/specifications";

export default {
  components: { addPro },
  name: "manage",
  dicts: ["sys_menus_status", "sys_menus_menus"],
  data() {
    return {
      menusId: 0,
      brand: [], //单位
      cate: [], //菜谱
      specifications: [], //规格
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 菜谱表格数据
      menusList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数

      sendTime: undefined,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        schoolName:undefined,
        "params[id]": undefined,
        "params[companyName]": undefined,
        "params[sendTimeStart]": undefined,
        "params[sendTimeEnd]": undefined,
        cateId: 0,
      },
      // 表单参数
      form: {},
      // 表单校验
    };
  },
  created() {
    this.queryParams.cateId = this.$route.params.cid;
    // console.log()
    this.getList();

    // this.show();
    //   import { getFormatbrandData } from "@/api/system/brand";
    //   import { getFormatCateData } from "@/api/system/cate";
    //   import { getFormatSpecData } from "@/api/system/specifications";
  },
  methods: {
    seeExpo(row) {
      let routeData = this.$router.resolve({
        path: "export?id=" + row.id, // path 要跳转的路由地址
        // query 要传递的参数
        query: {
          id: row.id,
          // type: this.type,
          // date: this.date,
        },
      });
      window.open(routeData.href, "_blank");
      // this.$router.push({ path: "export?id=" + row.id }).catch(() => {});
    },
    /** 提交按钮 */
    submitForm: function () {
      this.open = false;
      this.getList();
    },
    // cancel()
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          done();
        })
        .catch((_) => {});
    },

    /** 查询菜谱列表 */
    getList() {
      this.loading = true;
      getDelivery(this.queryParams).then((response) => {
        this.menusList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        brandId: undefined, //单位id
        cateId: this.queryParams.cateId, //行业菜谱id
        demand: undefined, //要求
        name: undefined, //名称
        other: undefined, //其他
        packages: undefined, //包装
        parentId: -1, //上级分类id
        specId: undefined, //规格id
        id: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      if (this.sendTime != undefined && this.sendTime.length > 0) {
        var date = this.sendTime;
        this.queryParams["params[sendTimeStart]"] = date[0];
        this.queryParams["params[sendTimeEnd]"] = date[1];
      } else {
        this.queryParams["params[sendTimeStart]"] = undefined;
        this.queryParams["params[sendTimeEnd]"] = undefined;
      }
      // console.log(this.queryParams.sendTime)
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    //点击添加
    handleAdd() {
      this.menusId = 0;
      this.open = true;
      this.title = "添加采购单";
    } /** 导出按钮操作 */,
    handleExport() {
      // http://localhost:8081/system/delivery/export
      this.download(
        "/system/delivery/export",
        {
          ...this.queryParams,
        },
        `采购单_${new Date().getTime()}.xlsx`
      );
    },
    seeInfo(row) {
      // console.log(row);
      this.open = true;
      this.menusId = row.id;
      this.title = "编辑采购单";
      // getDeliveryInfo(row.id).then((response) => {
      //   // console.log(response);
      // });
    },
  },
};
</script>
    